package com.shop.mapper;

import com.shop.pojo.Phone;
import com.shop.pojo.PhoneDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import java.util.List;

public interface PhoneMapper {
    @Select("select * from shop")
    List<Phone> findAll();

    @Select("select * from shop where name like concat('%',#{value},'%')")
    List<Phone> findByNameLike(String name);


    @Select("select * from shop where name like concat(#{name},'%') and stock>#{stock}")
    List<Phone> findByNameAndStock(@Param("name") String name,@Param("stock") Integer stock);

    /**
     * #{name}以及#{stock}中的name和stock必须是参数PhoneDTO中的写的属性名高度保持一致
     * @param phoneDTO
     * @return
     */
    @Select("select * from shop where name like concat(#{name},'%') and stock>#{stock}")
    List<Phone> findByPhoneDTO(PhoneDTO phoneDTO);

    //DML操作 update delete insert
    //返回类型设置成int类型=>受影响的行数.
    //如果保存失败的话,返回数字0
    @Insert("insert into shop(name,img_url,stock,create_date) values(#{name},#{imgUrl},#{stock},#{createDate})")
    int save(Phone phone);


}
